﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WpfAgendaContato.Modelos;
using System.Collections;
using System.Data;
using Oracle.DataAccess.Client;

namespace WpfAgendaContato.Persistencia
{
    public class PersistenciaCadastro
    {
        private int tamanho;
        private int indiceDeUso;
        private Pessoa[] array;
        private String Str_Connection = Dados.stringDeConexao;
        private String Str_Command = "";
        
        public PersistenciaCadastro()
        {
            try
            {
                OracleConnection Connection = new OracleConnection(Str_Connection);
                Str_Command = String.Format("INSERT INTO PESSOA(NOME) VALUES (FELIPE)");
                OracleCommand Command = new OracleCommand();
                Command.CommandText = Str_Command;
                Command.Connection = Connection;
                Connection.Open();
                Command.ExecuteNonQuery();
                Connection.Close();
            }
            catch (Exception)
            {
                throw new Exception("2");
            }
        }
        public void incluir(Pessoa objeto)
        {
            OracleConnection Connection = new OracleConnection(Str_Connection);
            Str_Command = String.Format("INSERT INTO PESSOA(NOME) VALUES (FELIPE)");
            OracleCommand Command = new OracleCommand();
            Command.CommandText = Str_Command;
            Command.Connection = Connection;
            Connection.Open();
            Command.ExecuteNonQuery();
            Connection.Close();
            if (indiceDeUso == tamanho)
            {
                throw new Exception("3");
            }
            array[indiceDeUso] = objeto;
            indiceDeUso++;
        }

        public ArrayList listar()
        {
            try
            {
                ArrayList colecao = new ArrayList();
                for (int pos = 0; pos < indiceDeUso; pos++)
			    {
			        colecao.Add(array[pos]);
			    }
                return colecao;
            }
            catch (Exception)
            {
                throw new Exception("4");
            }
        }

    }
}
